import PdfInvoiceResult from "../models/PdfInvoiceResult.ts";
import { ColumnProps } from "@douyinfe/semi-ui/lib/es/table";
import { Table, Tag } from "@douyinfe/semi-ui";

const columnGroups: ColumnProps<PdfInvoiceResult> = [
    {
        title: '序号',
        align: 'center' as const,
        render: (_: any, __: any, index: number) => {
            return index + 1
        }
    },
    {
        title: '文件名',
        align: 'center' as const,
        dataIndex: 'fileName'
    },
    {
        title: '处理状态',
        align: 'center' as const,
        render: (_: any, result: PdfInvoiceResult) => {
            if (result.success) {
                return <Tag color="green" type="solid" >处理成功 </Tag >
            }
            return <Tag color="pink" >处理失败 </Tag >
        }
    },
    {
        title: '发票代码',
        align: 'center' as const,
        render: (_: any, record: PdfInvoiceResult) => {
            if (!record.success) return null;
            return record.invoice?.code;
        }
    },
    {
        title: '发票号码',
        align: 'center' as const,
        render: (_: any, record: PdfInvoiceResult) => {
            if (!record.success) return null;
            return record.invoice?.number;
        }
    },
    {
        title: '金额',
        align: 'center' as const,
        render: (_: any, record: PdfInvoiceResult) => {
            if (!record.success) return null;
            return record.invoice?.totalAmount?.toFixed(2);
        }
    }
];

export default ({ pdfInvoices }: { pdfInvoices: PdfInvoiceResult[] }) => {
    return <Table id="current-weather-table" columns={columnGroups as any} dataSource={pdfInvoices} pagination={false} bordered={true} />
}